#--
# Project:	pkgman
# File:		pkgman/Rakefile
# Revision:	$Id: Rakefile 314 2008-01-04 22:15:15Z someword $
# Home:         http://code.google.com/p/pkgman/
# Author:	Derek Olsen <someword at gmail dot com>
# Copyright:	(c) 2007 by Derek Olsen
# License:	GNU General Public License v2 
#++

require 'rake/rdoctask'
 
# Define the usage message which will be displayed when rake is run with
# no arguments.
usage = <<_EOF

 The default task prints this usage.
 
 The other available tasks and their functions are
 rdoc    - Create the ruby rdoc documentation.
 dryrun  - Report what actions would be taken but dont do anything.
 pkgman  - Execute pkgman and perform the required package actions.
 mkpkg   - Create an solaris pkgman pkg
 t_up    - Run the package upgrade unit test
 t_mir   - Test the multiple install and remove
 t_key   - Test key checking logic 
 t_gz    - Test handling of gzipped files
 t_cmd   - Test that cmd prefix get's set correctly
 t_zn    - Test handling of zones
 t_all   - Execute all tests
_EOF

#
# File sets
#
PKGMAN_FILES   = FileList['bin/pkgman.rb']

#
# Documentation
#

desc "Generate rdoc documents for pkgman."
Rake::RDocTask.new(:rdoc) do |rdoc|
  rdoc.rdoc_dir = 'docs'
  rdoc.title    = 'pkgman'
  rdoc.options << '--line-numbers' << '--inline-source'
  rdoc.rdoc_files = PKGMAN_FILES 
end


# Define the config file name
conf = "pkgman.yaml"

# Define the default task
desc "Pring usage"

task :default do
  puts usage
end


# Alias the help taks to default
desc "Pring usage"
task :help => :default

# Make an pkgman pkg
task :mkpkg do
 system("./test/make_pkgman_pkg.rb")
end

# Prepare the test environment
task :t_prep do
  Dir.chdir("test")
  system("./make_pkgs.rb >/dev/null 2>&1") unless File.directory?("pkgs")
  system("./serve_pkgs.rb >/dev/null 2>&1 &")
  Dir.chdir("..")
end

# Cleanup after the tests
task :t_clean do
  system("/usr/bin/pkill -f 'ruby ./serve_pkgs.rb' >/dev/null 2>&1")
end

# Perform the package upgrade test
task :t_up do
  Dir.chdir("test")
  system "./test_upgrade_prep.rb"
  system "./test_pkgman.rb -f conf/pkg_upgrade.yaml -- --name test_package_upgrade"
  Dir.chdir("..")
end

# Perform the multiple install and remove test
task :t_mir do
  Dir.chdir("test")
  system "./test_multiple_prep.rb"
  system "./test_pkgman.rb -f conf/pkg_install_and_remove.yaml -- --name test_multiple_install_and_remove"
  Dir.chdir("..")
end

# Perform the key checking verification tests
task :t_key do
  Dir.chdir("test")
  system "./test_pkgman.rb -f conf/missing_keys.yaml -- --name=/missing_key/" 
  Dir.chdir("..")
end

# Make sure gzipped files get decompressed
task :t_gz do
  Dir.chdir("test")
  system "./test_pkgman.rb -f conf/missing_keys.yaml -- --name=test_gzipped_file"
  Dir.chdir("..")
end

# Make sure the cmd_prefix get's set appropriately
task :t_cmd do
  Dir.chdir("test")
  system "./test_pkgman.rb -f conf/missing_keys.yaml -- --name=/test_settings_cmd_prefix/"
  Dir.chdir("..")
end

# Make sure the flag passed to pkgadd is correct based off of OS release
task :t_zn do
  Dir.chdir("test")
  system "./test_pkgman.rb -f conf/zone_test.yaml -- --name=test_solaris_release_pkgadd_args"
  Dir.chdir("..")
end

task :t_all => [:t_prep, :t_gz, :t_key, :t_up, :t_mir, :t_cmd, :t_zn, :t_clean ]
